﻿// CameraSensor
// Object representing camera sensor properties
// 
// FLMScan - Featured by FabLab Munich

using System;
using FLMScan.Parameters;

namespace FLMScan.WorldCoordinateReconstruction.Riedmaier
{
    public class CameraSensor
    {
        private CameraSensorParameters cameraSensorParameters;
        private double pixelWidth;
        private double pixelHeight;
        private double focalLengthInPixelsX;
        private double focalLengthInPixelsY;
        private double focalLengthInMillimetersX;
        private double focalLengthInMillimetersY;
        private double primaryPointInPixelsX;
        private double primaryPointInPixelsY;
        private double distortionCoefficient1;
        private double distortionCoefficient2;
        private double distortionCoefficient3;
        private double distortionCoefficient4;

        public CameraSensor(CameraSensorParameters parameters)
        {
            cameraSensorParameters = parameters;

            pixelWidth = cameraSensorParameters.SensorWidth / cameraSensorParameters.ResolutionX;
            pixelHeight = cameraSensorParameters.SensorHeight / cameraSensorParameters.ResolutionY;
            focalLengthInPixelsX = cameraSensorParameters.FocalLengthInPixelsX;
            focalLengthInPixelsY = cameraSensorParameters.FocalLengthInPixelsY;
            focalLengthInMillimetersX = focalLengthInPixelsX * pixelWidth;
            focalLengthInMillimetersY = focalLengthInPixelsY * pixelHeight;
            primaryPointInPixelsX = cameraSensorParameters.PrimaryPointInPixelsX;
            primaryPointInPixelsY = cameraSensorParameters.PrimaryPointInPixelsY;
            distortionCoefficient1 = cameraSensorParameters.DistortionCoefficient1;
            distortionCoefficient2 = cameraSensorParameters.DistortionCoefficient2;
            distortionCoefficient3 = cameraSensorParameters.DistortionCoefficient3;
            distortionCoefficient4 = cameraSensorParameters.DistortionCoefficient4;
        }

        public double ConvertPixelsToMillimetersX(double pixels)
        {
            return pixelWidth * pixels;
        }

        public double ConvertPixelsToMillimetersY(double pixels)
        {
            return pixelHeight * pixels;
        }

        public double SensorWidth
        {
            get { return cameraSensorParameters.SensorWidth; }
        }

        public double SensorHeight
        {
            get { return cameraSensorParameters.SensorHeight; }
        }

        public int ResolutionX
        {
            get { return cameraSensorParameters.ResolutionX; }
        }

        public int ResolutionY
        {
            get { return cameraSensorParameters.ResolutionY; }
        }
        
        public double FocalLengthInPixelsX
        {
            get { return focalLengthInPixelsX; }
        }

        public double FocalLengthInPixelsY
        {
            get { return focalLengthInPixelsY; }
        }

        public double FocalLengthInMillimetersX
        {
            get { return focalLengthInMillimetersX; }
        }

        public double FocalLengthInMillimetersY
        {
            get { return focalLengthInMillimetersY; }
        }

        public double PrimaryPointInPixelsX
        {
            get { return primaryPointInPixelsX; }
        }

        public double PrimaryPointInPixelsY
        {
            get { return primaryPointInPixelsY; }
        }

        public double DistortionCoefficient1
        {
            get { return distortionCoefficient1; }
        }

        public double DistortionCoefficient2
        {
            get { return distortionCoefficient2; }
        }

        public double DistortionCoefficient3
        {
            get { return distortionCoefficient3; }
        }

        public double DistortionCoefficient4
        {
            get { return distortionCoefficient4; }
        }
    }
}
